using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace MEA.AE_BusinessLogic
{
	public class FileInfoHnd
	{
		public bool fileinfoShowed;

		private int infoBoxHigh;

		private MemoryStream userInput;

		private UIFileInfo uiFileInfo;

		private Point fileInfoPos;

		public FileInfoHnd()
		{
			fileinfoShowed = false;
			userInput = null;
			infoBoxHigh = 0;
			uiFileInfo = null;
		}

		public void ShowFileInfo()
		{
			if (uiFileInfo != null)
			{
				if (!fileinfoShowed)
				{
					uiFileInfo = new UIFileInfo(userInput, infoBoxHigh, fileInfoPos);
					uiFileInfo.FormClosing += b_FileInfoFormClosed;
				}
				uiFileInfo.Show();
				uiFileInfo.Focus();
				fileinfoShowed = true;
			}
			else
			{
				uiFileInfo = new UIFileInfo(userInput, infoBoxHigh, fileInfoPos);
				uiFileInfo.FormClosing += b_FileInfoFormClosed;
				uiFileInfo.Show();
				uiFileInfo.Focus();
				fileinfoShowed = true;
			}
		}

		public void SetFileInfoStrm(ref Xml_Log.CXmlFileLogInfo sInfo, Point showPos)
		{
			fileInfoPos = showPos;
			string text = "{\\rtf1\r\n";
			if (sInfo == null || userInput != null)
			{
				return;
			}
			infoBoxHigh = 0;
			if (sInfo.fileCreation != null)
			{
				text += "\\b File Id \\b0 ";
				text += string.Format("\\line File name:              {0}", sInfo.filename);
				infoBoxHigh += 2;
			}
			if (sInfo.fileCreation != null)
			{
				text += string.Format("\\line File created at:        {0}", sInfo.fileCreation);
				infoBoxHigh++;
			}
			if (sInfo.swName != null && sInfo.swVer != null)
			{
				text += "\\line \\line \\b SW Id \\b0 ";
				text += string.Format("\\line Wizard: \\b {0} {1}\\b0", sInfo.swName, sInfo.swVer);
				infoBoxHigh += 2;
			}
			if (sInfo.ecuSWVer != null)
			{
				text += string.Format("\\line ECU SW-Version:         {0}", sInfo.ecuSWVer);
				infoBoxHigh++;
			}
			if (sInfo.ecuSWRevisionA != null)
			{
				text += string.Format("\\line ECU SW Revision Nr. A:    {0}", sInfo.ecuSWRevisionA);
				infoBoxHigh++;
			}
			if (sInfo.ecuSWRevisionB != null)
			{
				text += string.Format("\\line ECU SW Revision Nr. B:    {0}", sInfo.ecuSWRevisionB);
				infoBoxHigh++;
			}
			if (sInfo.engineTypeA != null)
			{
				text += "\\line \\line \\b Engine Id \\b0 ";
				text += string.Format("\\line Engine Type A:          {0}", sInfo.engineTypeA);
				infoBoxHigh += 2;
			}
			if (sInfo.engineTypeB != null)
			{
				text += string.Format("\\line Engine Type B:          {0}", sInfo.engineTypeB);
				infoBoxHigh++;
			}
			if (sInfo.engineSerNrA != null)
			{
				text += string.Format("\\line Engine Serial Nr. A:    {0}", sInfo.engineSerNrA);
				infoBoxHigh++;
			}
			if (sInfo.engineSerNrB != null)
			{
				text += string.Format("\\line Engine Serial Nr. B:    {0}", sInfo.engineSerNrB);
				infoBoxHigh++;
			}
			if (sInfo.engineTimeA != null)
			{
				text += string.Format("\\line Engine Time:              {0}", sInfo.engineTimeA);
				infoBoxHigh++;
			}
			if (sInfo.engineTimeB != null)
			{
				text += string.Format("\\line Engine Time:              {0}", sInfo.engineTimeB);
				infoBoxHigh++;
			}
			if (sInfo.ecuType != null)
			{
				text += "\\line \\line \\b ECU Id \\b0 ";
				text += string.Format("\\line ECU Type:                     {0}", sInfo.ecuType);
				infoBoxHigh += 2;
			}
			if (sInfo.ecuSerialNrA != null)
			{
				text += string.Format("\\line ECU Serial Nr. A:           {0}", sInfo.ecuSerialNrA);
				infoBoxHigh++;
			}
			if (sInfo.ecuSerialNrB != null)
			{
				text += string.Format("\\line ECU Serial Nr. B:           {0}", sInfo.ecuSerialNrB);
				infoBoxHigh++;
			}
			if (sInfo.ecuHWRevisionA != null)
			{
				text += string.Format("\\line ECU HW Revision Nr. A:    {0}", sInfo.ecuHWRevisionA);
				infoBoxHigh++;
			}
			if (sInfo.ecuHWRevisionB != null)
			{
				text += string.Format("\\line ECU HW Revision Nr. B:    {0}", sInfo.ecuHWRevisionB);
				infoBoxHigh++;
			}
			if (sInfo.ecuTotalTimeA != null)
			{
				text += string.Format("\\line ECU Total Time A:         {0}", sInfo.ecuTotalTimeA);
				infoBoxHigh++;
			}
			if (sInfo.ecuTotalTimeB != null)
			{
				text += string.Format("\\line ECU Total Time B:         {0}", sInfo.ecuTotalTimeB);
				infoBoxHigh++;
			}
			if (sInfo.ecuTotalActTimeA != null)
			{
				text += string.Format("\\line ECU Total Act. Time A:    {0}", sInfo.ecuTotalActTimeA);
				infoBoxHigh++;
			}
			if (sInfo.ecuTotalActTimeB != null)
			{
				text += string.Format("\\line ECU Total Act. Time B:    {0}", sInfo.ecuTotalActTimeB);
				infoBoxHigh++;
			}
			if (sInfo.ecuRTCA != null)
			{
				text += string.Format("\\line ECU RTC Time A:             {0}", sInfo.ecuRTCA);
				infoBoxHigh++;
			}
			if (sInfo.ecuRTCB != null)
			{
				text += string.Format("\\line ECU RTC Time B:             {0}", sInfo.ecuRTCB);
				infoBoxHigh++;
			}
			bool flag = false;
			if (sInfo.powerLewerWarnList != null)
			{
				for (int i = 0; i < sInfo.powerLewerWarnList.Count; i++)
				{
					if (sInfo.powerLewerWarnList[i] != string.Empty)
					{
						flag = true;
					}
				}
				if (flag)
				{
					text += "\\line \\line \\b Power lever warnings:\\b0\\line High power for too long time";
					infoBoxHigh++;
					foreach (string powerLewerWarn in sInfo.powerLewerWarnList)
					{
						if (powerLewerWarn != string.Empty)
						{
							text += string.Format("\\line {0}", powerLewerWarn);
							infoBoxHigh++;
						}
					}
					infoBoxHigh += 10;
				}
			}
			flag = false;
			if (sInfo.ecuSectorWarnList != null)
			{
				for (int j = 0; j < sInfo.ecuSectorWarnList.Count; j++)
				{
					if (sInfo.ecuSectorWarnList[j] != string.Empty)
					{
						flag = true;
					}
				}
				if (flag)
				{
					text += "\\line \\line \\b Sector Warnings:\\b0 ";
					infoBoxHigh++;
					foreach (string ecuSectorWarn in sInfo.ecuSectorWarnList)
					{
						if (ecuSectorWarn != string.Empty)
						{
							text += string.Format("\\line {0}", ecuSectorWarn);
							infoBoxHigh++;
						}
					}
				}
			}
			flag = false;
			if (sInfo.ecuLiLoWarnList != null)
			{
				for (int k = 0; k < sInfo.ecuLiLoWarnList.Count; k++)
				{
					if (sInfo.ecuLiLoWarnList[k] != string.Empty)
					{
						flag = true;
					}
				}
				if (flag)
				{
					text += "\\line \\line \\b Lead-In Lead-Out  Warnings:\\b0 ";
					infoBoxHigh++;
					foreach (string ecuLiLoWarn in sInfo.ecuLiLoWarnList)
					{
						if (ecuLiLoWarn != string.Empty)
						{
							text += string.Format("\\line {0}", ecuLiLoWarn);
							infoBoxHigh++;
						}
					}
				}
			}
			flag = false;
			if (sInfo.ecuEvRecWarnList != null)
			{
				for (int l = 0; l < sInfo.ecuEvRecWarnList.Count; l++)
				{
					if (sInfo.ecuEvRecWarnList[l] != string.Empty)
					{
						flag = true;
					}
				}
				if (flag)
				{
					string text2 = string.Format("{0:7}:     {1:37}:                {2:27}:  {3:18}: {4:9}: {5:14}", "ECU", "Time stamp", "Ev.ID", "EV.State", "EV.Count", "EV.description");
					text = text + "\\line \\line \\b Event Recorder Warnings:\\b0 \\line Time stamp Error \\line " + text2;
					infoBoxHigh++;
					foreach (string ecuEvRecWarn in sInfo.ecuEvRecWarnList)
					{
						if (ecuEvRecWarn != string.Empty)
						{
							text += string.Format("\\line {0}", ecuEvRecWarn);
							infoBoxHigh++;
						}
					}
				}
			}
			byte[] array = new byte[text.Length + 1];
			for (int m = 0; m < text.Length; m++)
			{
				array[m] = (byte)text[m];
			}
			array[text.Length] = 13;
			userInput = new MemoryStream(array);
			userInput.Position = 0L;
		}

		public void SetShow()
		{
			uiFileInfo.Show();
		}

		public void SetFocus()
		{
			uiFileInfo.Focus();
		}

		public void Disp()
		{
			if (uiFileInfo != null)
			{
				uiFileInfo.Dispose();
			}
			fileinfoShowed = false;
		}

		private void b_FileInfoFormClosed(object sender, FormClosingEventArgs e)
		{
			Disp();
		}
	}
}
